package HGbet;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Vector;

import javax.swing.AbstractButton;
import javax.swing.AbstractCellEditor;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;








import DXQclient.DXQClientThread;
import DXQclient.DXQclientManager;
import P8.StoneAgeClient;


/**
 * 多账号管理界面
 * 
 * @date 2017年12月22日 上午10:36:13
 * @author lin
 *
 */

public class BetAccountsListWindow extends JFrame{

	private static final long serialVersionUID = 101L;
	
	private static final int btnWidth = 40;
	private static final int btnHeight = 15;
	
	//控件
	JButton addButton = null;
	JButton startButton = null;
	MyTableModel tableMode = null;    
	JTable table = null;	
	
	public Vector<Object[]> showitemVec = null;
	//end 控件
	
	
	
	
	JLabel statusLabel=new JLabel("皇冠:      账号未登陆");
	
	
	JLabel serverstatusLabel=new JLabel("服务器状态:      已连接");
	
	
	
	JToolBar toolbar = new JToolBar();
	
	
	
	
	
	
	public Vector<String[]> betItemsVec = new Vector<String[]>();
	
	Vector<DXQclientManager> dxqClientManagers = null; //manager容器
	Vector<DXQClientThread> dxqClientThreads = null;   //线程容器
	boolean needUpdateAccounts = true;
	boolean inited = false;
	boolean startBet = false;
	
	/**
	 * 构造函数
	 */
	public BetAccountsListWindow() {	
		addButton = new JButton("添加投注");
		startButton = new JButton("开始投注");
		tableMode = new MyTableModel();  
		table = new JTable(tableMode); 
		showitemVec = new Vector<Object[]>();
		dxqClientManagers = new Vector<DXQclientManager>();
		dxqClientThreads = new Vector<DXQClientThread>();
		
		setTitle("投注管理");
		
		statusLabel.setForeground(Color.red);
	}
	
	public void setstatusLabeltext(String str){
		statusLabel.setText("皇冠:      " + str);
	}
	
	public void setstatusLabelcolor(Color cr){
		statusLabel.setForeground(cr);
	}
	
	
	
	public void setserverstatusLabeltext(String str){
		serverstatusLabel.setText("服务器:      " + str + "                                                         ");
	}
	
	public void setserverstatusLabelcolor(Color cr){
		serverstatusLabel.setForeground(cr);
	}
	
	
	/**
	 * 界面初始化
	 */
	public void Init() {
		if(inited) {
			return;
		}
		inited = true;
		
		//container init
		final Container container = getContentPane();
		container.setLayout(new BorderLayout());
		//end container init
		
		JPanel panelNorth = new JPanel(new GridLayout(1, 1));
        container.add(panelNorth, BorderLayout.NORTH); 
        
       toolbar.setLayout(new FlowLayout(FlowLayout.RIGHT));
        
       // Insets is = new Insets(0,0,);
        
       // toolbar.setMargin(Insets);
        
       
       toolbar.add(serverstatusLabel);
       
        toolbar.add(statusLabel);
        
       
        
       
        
        container.add(toolbar,BorderLayout.SOUTH);
		
		//button init
        addButton.setSize(btnWidth, btnHeight);
        addButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Object [] objdata = new Object[16];
		        objdata[0] = false;
		        objdata[1] = "http://66.133.86.54/";
		        
		        int max = 0;
		        for(int i = 0; i < showitemVec.size(); i++){
		        	
		        	
		        	int num = Integer.parseInt((showitemVec.elementAt(i)[2]+"").split("_")[1]);
		        	if(num > max){
		        		max = num;
		        	}
		        	
		        }
		        
		        int newNum = max +1;
		        String betItemStr = Integer.toString(newNum);
		        
		        String[] newBetItem = {"false",  "http://66.133.86.54/", betItemStr};
		        
		        objdata[2] = "bet_" + betItemStr;
		        
		       
		        
		        
		        betItemsVec.add(newBetItem);
		        
		        
		        
		        
		        objdata[10] = "查看详情";
		        objdata[11] = "删除";
		        showitemVec.add(objdata);
		        
		        updateAccountsList();
		        
		        DXQclientManager manager = new DXQclientManager();
		        manager.setAccount("bet_" + betItemStr);
		        dxqClientManagers.add(manager);

		        
		        
		        tableMode.updateTable();
			}
		});
        
        startButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(startBet) {
					startBet = false;
					startButton.setText("开始投注");
					
					DXQclientManager.setStartBet(startBet);
					
					
/*					int index = 0;
					for(DXQclientManager manager : dxqClientManagers) {
						
						
						manager.setOnline(false);
						index++;
					}*/
					tableMode.updateTable();
				} else {
					startBet = true;
					startButton.setText("停止投注");
					
					DXQclientManager.setStartBet(startBet);
					
					
					tableMode.updateTable();
				}
			}
		});
        
        panelNorth.add(addButton);
        panelNorth.add(startButton);
		//end button init
		
		//scroll init
		JScrollPane scroll = new JScrollPane(table); 
		container.add(scroll, BorderLayout.CENTER);  
		//end scroll init
		
		//talbe init
		table.getColumnModel().getColumn(0).setPreferredWidth(20);//
        table.getColumnModel().getColumn(1).setPreferredWidth(100);//

	    
	    table.getColumnModel().getColumn(2).setMinWidth(0);   
	    table.getColumnModel().getColumn(2).setMaxWidth(0);
	    table.getColumnModel().getColumn(2).setWidth(0);
	    table.getColumnModel().getColumn(2).setPreferredWidth(0);
	    
	    
	    
	    
	    table.getColumnModel().getColumn(3).setPreferredWidth(80);//
	    table.getColumnModel().getColumn(4).setPreferredWidth(30);//
	    table.getColumnModel().getColumn(0).setCellEditor(new CheckBoxCellEditor());
        table.getColumnModel().getColumn(0).setCellRenderer(new CWCheckBoxRenderer());
	    
	    table.setRowHeight(30);
	    table.setFont(new java.awt.Font("微软雅黑", Font.PLAIN, 13));
	    DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();// 设置table内容居中
        tcr.setHorizontalAlignment(JLabel.CENTER);
        
        table.setDefaultRenderer(Object.class, tcr);
        table.addMouseListener(new MouseAdapter(){//设置鼠标点击响应
            public void mouseClicked(MouseEvent e){
            	
            	int columnIndex = table.columnAtPoint(e.getPoint()); //获取点击的列
                int rowIndex = table.rowAtPoint(e.getPoint()); //获取点击的行
                
                if(columnIndex == 10) { //查看详细
	                
	                	if(dxqClientManagers != null) {
	           		 		dxqClientManagers.elementAt(rowIndex).showbetlistwnd();
	                	}
		           	
                }
                
                if(columnIndex == 11) { //删除账号
                	int n = JOptionPane.showConfirmDialog(null, "确认删除吗?", "删除账号", JOptionPane.YES_NO_OPTION);
    				if (n == JOptionPane.YES_OPTION) {
	            		
	            		dxqClientManagers.remove(rowIndex);
	            		
	            		
	            		removeRelatedfiles((String)showitemVec.elementAt(rowIndex)[2]);
	            		
	            		showitemVec.remove(rowIndex);
	            		tableMode.updateTable();
	            		updateAccountsList();
    				}
                }
                
                if(e.getClickCount() == 1){ //单击自动登录
                    if(columnIndex == 0) {//第0列时，执行代码
                        if(table.getValueAt(rowIndex,columnIndex) == null){ //如果未初始化，则设置为false
                        	table.setValueAt(false, rowIndex, columnIndex);
                          }

                        if(((Boolean)table.getValueAt(rowIndex,columnIndex)).booleanValue()){ //原来选中
                        	showitemVec.elementAt(rowIndex)[columnIndex] = false;
                        	
                        	
                        	dxqClientManagers.elementAt(rowIndex).setOnline(false);
                        	dxqClientManagers.elementAt(rowIndex).setBet(false);
                        	tableMode.updateTable();
                        	updateAccountsList();
                          }
                        else {//原来未选中
                        	showitemVec.elementAt(rowIndex)[columnIndex] = true;
                        	dxqClientManagers.elementAt(rowIndex).setBet(true);
                        	
                        	
                        	tableMode.updateTable();
                        	updateAccountsList();
                          }
                     } 
                }
	               	
            }
        });
        //end table init
        
        //设置窗口大小
        setBounds(100, 100, 1600, 800); 
        
        readAccountsList();
	}
	
	/**
	 * 读取账号列表文件
	 */
	private void readAccountsList() {
		File file = new File("account/" + "accountslist.txt");
		
		if(!file.exists()) {
			System.out.println("[readAccountsList] 文件不存在");
			return;
		}
		
		BufferedReader freader = null;
		try {
			freader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
			
			String str = "";
			while ((str = freader.readLine()) != null) {
				String[] contents = str.split(",");
				if(contents.length == 3){
					Object [] objdata = new Object[16];
					Boolean b = Boolean.parseBoolean(contents[0]);
			        objdata[0] = b;
			        objdata[1] = contents[1];
			        objdata[2] = contents[2];
			        
			        
			        
			        objdata[10] = "查看详情";
			        objdata[11] = "删除";
			        showitemVec.add(objdata);
			        
			        DXQclientManager manager = new DXQclientManager();
			        dxqClientManagers.add(manager);
			        manager.setAccount(contents[2]);
			        manager.setBet(b);
			        
			        //to do
			        manager.recoverBetlistVecfromefile();
			        manager.betsetWnd.recoverbetparamsfromfile();
			       // manager.sethgstatustxt(contents[2] + " 离线");
			     		        
				}
			}
			
			freader.close();
			
			
			
			
		} catch(FileNotFoundException e) {
			e.printStackTrace();
			return;
		} catch(IOException e) {
			e.printStackTrace();
			return;
		}
					
	}
	
	
	/**
	 * 
	 * 同步账号列表到文件
	 * 
	 */
	public void updateAccountsList() {		
		try{	
			File file = new File("account/" + "accountslist.txt");

			if(!file.exists()){	
				file.createNewFile();
			}
			
			BufferedWriter fwlocal = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "UTF-8"));

			String str = "";
			for(Object [] obs : showitemVec) {
				str = obs[0] + "," + obs[1] + "," + obs[2];
				fwlocal.append(str);
				fwlocal.newLine();
				fwlocal.flush();
			}

			fwlocal.close();
	
		}catch(FileNotFoundException e) {
			e.printStackTrace();
			return;
		} catch(IOException e) {
			e.printStackTrace();
			return;
		}
	}
	
	public void removeRelatedfiles(String name){
		
		try{
			
			delFolder("data/" + name);
			
			delFolder("hgbetdata/" + name);
			
		}catch(Exception e){
			e.printStackTrace();
		}
		
	}
	
	
	public static void delFolder(String folderPath) {  
	     try {  
	        delAllFile(folderPath); //删除完里面所有内容  
	        String filePath = folderPath;  
	        filePath = filePath.toString();  
	        java.io.File myFilePath = new java.io.File(filePath);  
	        myFilePath.delete(); //删除空文件夹  
	     } catch (Exception e) {  
	       e.printStackTrace();   
	     }  
	}  
	
	public static boolean delAllFile(String path) {  
	       boolean flag = false;  
	       File file = new File(path);  
	       if (!file.exists()) {  
	         return flag;  
	       }  
	       if (!file.isDirectory()) {  
	         return flag;  
	       }  
	       String[] tempList = file.list();  
	       File temp = null;  
	       for (int i = 0; i < tempList.length; i++) {  
	          if (path.endsWith(File.separator)) {  
	             temp = new File(path + tempList[i]);  
	          } else {  
	              temp = new File(path + File.separator + tempList[i]);  
	          }  
	          if (temp.isFile()) {  
	             temp.delete();  
	          }  
	          if (temp.isDirectory()) {  
	             delAllFile(path + "/" + tempList[i]);//先删除文件夹里面的文件  
	             delFolder(path + "/" + tempList[i]);//再删除空文件夹  
	             flag = true;  
	          }  
	       }  
	       return flag;  
	     }  
	
	
	
	
	
	
	
	
	/**
	 * 登录成功后更新界面显示
	 * @param manager
	 */
/*	public void setLoginSuccess(DXQclientManager manager, boolean res) {
		if(res) {
			int index = 0;
			for(DXQclientManager ma : dxqClientManagers) {
				if(ma == manager) {
					showitemVec.elementAt(index)[4] = "在线";
					break;
				}
				index++;
			}
			
			if(needUpdateAccounts) {//若更新了登录信息则保存到文件
				updateAccountsList();
				needUpdateAccounts = false;
			}
		} else {
			int index = 0;
			for(DXQclientManager ma : dxqClientManagers) {
				if(ma == manager) {
					showitemVec.elementAt(index)[4] = "登录失败";
					break;
				}
				index++;
			}
		}
		tableMode.updateTable();
	}*/
	
	public Vector<DXQclientManager> getManagers() {
		return dxqClientManagers;
	}
	
	
	
	
	
	
	/**
	 * 设置投注大小球盘口
	 */
	void setBetDxqpankou(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[4] = text;
				tableMode.updateTableCell(index, 4);
				break;
			}
			index++;
		}
	}
	
	
	/**
	 * 设置投注让球盘单式盘口
	 */
	void setBetRqpankou(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[5] = text;
				tableMode.updateTableCell(index, 5);
				break;
			}
			index++;
		}
	}
	
	
	/**
	 * 设置投注水位
	 */
	void setBetRatio(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[6] = text;
				tableMode.updateTableCell(index, 6);
				break;
			}
			index++;
		}
	}
	
	/**
	 * 设置投注金额
	 */
	void setBetAmount(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[7] = text;
				tableMode.updateTableCell(index, 7);
				break;
			}
			index++;
		}
	}
	
	
	/**
	 * 设置投注队次
	 */
	void setBetTimes(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[8] = text;
				tableMode.updateTableCell(index, 8);
				break;
			}
			index++;
		}
	}
	
	
	/**
	 * 设置投注金额
	 */
	void setBetAllTimes(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[9] = text;
				tableMode.updateTableCell(index, 9);
				break;
			}
			index++;
		}
	}
	
	
	
	/**
	 * 设置投注时间
	 */
	void setBetTime(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[3] = text;
				tableMode.updateTableCell(index, 3);
				break;
			}
			index++;
		}
	}
	
	
	
	
/*	*//**
	 * 设置单式大小盘口
	 *//*
	void setDanshiDxPankou(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[5] = text;
				tableMode.updateTableCell(index, 5);
				break;
			}
			index++;
		}
	}
	
	*//**
	 * 设置单式水位
	 *//*
	void setDanshiShuiwei(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[6] = text;
				tableMode.updateTableCell(index, 6);
				break;
			}
			index++;
		}
	}
	
	
	
	*//**
	 * 设置下半场大小盘口
	 *//*
	void setXiabanDxPankou(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[7] = text;
				tableMode.updateTableCell(index, 7);
				break;
			}
			index++;
		}
	}
	
	*//**
	 * 设置下半场水位
	 *//*
	void setXiabanShuiwei(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[8] = text;
				tableMode.updateTableCell(index, 8);
				break;
			}
			index++;
		}
	}
	
	*//**
	 * 设置自动投注
	 *//*
	void setZidongTouzhu(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[9] = text;
				tableMode.updateTableCell(index, 9);
				break;
			}
			index++;
		}
	}
	
	*//**
	 * 设置投注大小盘
	 *//*
	void setTouzhuDxPan(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[10] = text;
				tableMode.updateTableCell(index, 10);
				break;
			}
			index++;
		}
	}
	
	*//**
	 * 设置投注水位
	 *//*
	void setTouzhuShuiwei(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[11] = text;
				tableMode.updateTableCell(index, 11);
				break;
			}
			index++;
		}
	}
	
	*//**
	 * 设置投注金额
	 *//*
	void setTouzhuMoney123(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[12] = text;
				tableMode.updateTableCell(index, 12);
				break;
			}
			index++;
		}
	}
	
	*//**
	 * 设置投注时间间隔
	 *//*
	void setTimePeriod(DXQclientManager manager, String text) {
		int index = 0;
		for(DXQclientManager ma : dxqClientManagers) {
			if(ma == manager) {
				showitemVec.elementAt(index)[13] = text;
				tableMode.updateTableCell(index, 13);
				break;
			}
			index++;
		}
	}*/
	
	
	
	/**
	 * 
	 * TableModel类
	 *
	 */
	public class MyTableModel extends AbstractTableModel  
    {  
        /**
		 * 
		 */
		private static final long serialVersionUID = 1001L;

        String[] columnNames =  
        	 { "自动投注", "网址", "账号", "时间", "参与盘口", "让球盘", "水位", "投注金额" , "投注次数","总次","参数设置", "删除账号"};
        

        /** 
         * 得到数据所对应对象 
         */  
        @Override  
        public Object getValueAt(int rowIndex, int columnIndex)  
        {  	
        	try{
        			return showitemVec.elementAt(rowIndex)[columnIndex];  		
        	}catch(Exception e){
        		e.printStackTrace();
        		return null;
        	}
	
        }      
  
  
        /** 
         * 构造方法，初始化二维数组data对应的数据 
         */  
        public MyTableModel()  
        {  

        }  
  
        // 以下为继承自AbstractTableModle的方法，可以自定义  
        /** 
         * 得到列名 
         */  
        @Override  
        public String getColumnName(int column)  
        {  
            return columnNames[column];  
        }  
          
        /** 
         * 重写方法，得到表格列数 
         */  
        @Override  
        public int getColumnCount()  
        {  
            return columnNames.length;  
        }  
  
        /** 
         * 得到表格行数 
         */  
        @Override  
        public int getRowCount()  
        {         
	        if(null == showitemVec){
	    		return 0;
	    	}
	        
	        //System.out.println(gameDetailsVec.size());
	        
            return showitemVec.size();  
        }  
  
        /** 
         * 得到指定列的数据类型 
         */  
        @Override  
        public Class<?> getColumnClass(int columnIndex)  
        {  
            return String.class;
        }  
  
        /** 
         *设置可否编辑
         */  
        @Override  
        public boolean isCellEditable(int rowIndex, int columnIndex)  
        {  
        	if(columnIndex == 1 || columnIndex == 2 || columnIndex == 3) {
        		return true;
        	}
            return false;
        }  
          
        /** 
         * 如果数据单元为可编辑，则将编辑后的值替换原来的值 
         */  
        @Override  
        public void setValueAt(Object aValue, int rowIndex, int columnIndex)  
        {  
        	showitemVec.elementAt(rowIndex)[columnIndex] = aValue;
        	fireTableCellUpdated(rowIndex, columnIndex);
        	
        	if(columnIndex == 0) { //登录信息是否改变
        		betItemsVec.elementAt(rowIndex)[0] = showitemVec.elementAt(rowIndex)[0]+"";
        		updateAccountsList();
        		
        	} else if(columnIndex <= 3) {
        		needUpdateAccounts = true;
        		if(columnIndex == 1)
        			dxqClientManagers.elementAt(rowIndex).hgbet.setAddress(aValue.toString());
        		
        	}
            /*detailsData.elementAt(rowIndex)[columnIndex] = (String)aValue;  
            通知监听器数据单元数据已经改变  
            fireTableCellUpdated(rowIndex, columnIndex);  */
        }  
        
        public void updateTable(){
        	fireTableDataChanged();
        }
        
        public void updateTableCell(int rowIndex, int columnIndex){
        	fireTableCellUpdated(rowIndex, columnIndex);
        }
        
    }  //end class MyTableModel 
	
	/**
	 * 
	 * inner class 单选框
	 *
	 */
	class CheckBoxCellEditor extends AbstractCellEditor implements TableCellEditor {
	 
	  private static final long serialVersionUID = 1002L;

	  
	  protected JCheckBox checkBox;

	 
	  public CheckBoxCellEditor() {
	    checkBox = new JCheckBox();
	    checkBox.setHorizontalAlignment(SwingConstants.CENTER);
	    // checkBox.setBackground( Color.white);
	  }

	  
	  @Override public Object getCellEditorValue() {
	    return Boolean.valueOf(checkBox.isSelected());
	  }

	
	  @Override public Component getTableCellEditorComponent(
	    JTable  table,
	    Object  value,
	    boolean isSelected,
	    int     row,
	    int     column) {
	    checkBox.setSelected(((Boolean) value).booleanValue());

	    return checkBox;

	  }
	} // end inner class CheckBoxCellEditor

	/**
	 * 
	 * inner class CWCheckBoxRenderer
	 *
	 */
	class CWCheckBoxRenderer extends JCheckBox implements TableCellRenderer {
	  
	  private static final long serialVersionUID = 1003L;
	  
	  Border border = new EmptyBorder(1, 2, 1, 2);

	  public CWCheckBoxRenderer() {
	    super();
	    setOpaque(true);
	    setHorizontalAlignment(SwingConstants.CENTER);
	  }

	  @Override public Component getTableCellRendererComponent(
	    JTable  table,
	    Object  value,
	    boolean isSelected,
	    boolean hasFocus,
	    int     row,
	    int     column) {
	    if (value instanceof Boolean) {
	      setSelected(((Boolean) value).booleanValue());

	      // setEnabled(table.isCellEditable(row, column));
	      setForeground(table.getForeground());
	      setBackground(table.getBackground());

	    }

	    return this;
	  }
	} // end inner class CWCheckBoxRenderer
	
}
